import moment from 'moment'
import { mapGetters } from 'vuex'
import { startTransport } from '@/api/scene'

export default {
  computed: {
    ...mapGetters(['sceneId', 'userId'])
  },

  methods: {
    /**
     * 同步时钟
     * @author Farley
     * @date 2021-11-18
     * @returns {any}
     */
    syncClock(options, callback) {
      options.sceneId = this.sceneId
      options.userId = this.userId
      options.startTime ? options.startTime = moment(options.startTime).utc().format('YYYY-MM-DDTHH:mm:ss') + 'Z' : null
      // 时间轴改变，向后台发送请求同步时间
      startTransport(options).then(res => {
        if (res.data.code === 200) {
          if (typeof callback === 'function') {
            callback()
          }
        } else {
          this.$message.error('时钟同步失败')
        }
      }).catch(err => {
        this.$message.error('时钟同步失败 ' + err.message)
      })
    },
  }
}
